package com.demo.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.demo.entity.News;
import com.demo.server.NewsServer;
import com.jweb.annotaion.JAutowired;
import com.jweb.annotaion.JController;
import com.jweb.annotaion.JParam;
import com.jweb.core.handle.Controller;

/**
 * 2新闻
 * 
 * @author Yuan
 */
@JController("/news")
public class NewsController extends Controller {
	public void init() {
		setAttr("menutag", 2);
		setAttr("type", server.listAllType());
	}

	@JAutowired
	public NewsServer server;

	public void NewsManager(@JParam("${1}") int curPage, @JParam("${2}") int newType) {
		setAttr("result", server.listNews(curPage, newType));
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", curPage + "");
		map.put("name", server.getTypeByID(curPage));
		setAttr("Cur_Type", map);
		getHotlist();
	}

	public void NewsInfo() {
		News news = server.getNewsById(getParamURL_int(0));
		setAttr("info", news);
		int tid = server.TYPES.get(news.getType());
		Map<String, String> map = new HashMap<String, String>();
		map.put("id", tid + "");
		map.put("name", news.getType());
		setAttr("Cur_Type", map);
		getHotlist();
	}

	private void getHotlist() {
		List<Map<Integer, String>> list48 = server.listHot48();
		List<Map<Integer, String>> list7D = server.listHot7Day();
		List<Map<Integer, String>> listCom = server.listHotComment();
		List<Map<Integer, String>> listMon = server.listHotMonth();

		setAttr("list48", list48);
		setAttr("list7D", list7D);
		setAttr("listCom", listCom);
		setAttr("listMon", listMon);
	}
}
